package dao

import (
	"github.com/gin-gonic/gin"
	"gorm.io/gorm"
	"time"
)

type Version struct {
	Id           int       `json:"id" gorm:"primary_key" description:"自增主键"`
	Platform     string    `json:"platform" gorm:"column:platform" description:"平台名称"`
	Version      string    `json:"version" gorm:"column:version" description:"平台版本"`
	VersionAlias int       `json:"version_alias" gorm:"column:version_alias" description:"平台版本100"`
	CreatedAt    time.Time `json:"created_at" gorm:"column:created_at" description:"创建时间"`
}

func (t *Version) TableName() string {
	return "edt_version"
}

func (t *Version) Find(c *gin.Context, tx *gorm.DB, platform string) (*Version, error) {
	version := &Version{}
	err := tx.WithContext(c).Where("platform = ?", platform).Order("version_alias desc").First(version).Error
	if err != nil {
		return nil, err
	}
	return version, nil
}
